import React, { Component, createRef } from 'react'

// 受控组件和非受控组件
export default class App extends Component {
  constructor(props) {
    super(props)
    this.ipt = createRef() // 函数
  }

  state = {
    textValue: 'hello'
  }
  
  handleChange(e) {
    console.log(e, this.state.textValue)
    this.setState({
      textValue: e.target.value
    })
  }

  render() {
    return (
      <div>
        {/* <input type="text" value={this.state.textValue} onChange={this.handleChange.bind(this)} /> */}
        <input type="text" onInput={this.handleChange.bind(this)} ref={this.ipt} />
      </div>
    )
  }

  componentDidMount() {
    setTimeout( () => {
      console.log(this.state.textValue)
    }, 2000 )
  }
}
